package iws.g5.uebung3.interfaces;

import iws.g5.uebung3.StateModel;
import iws.g5.uebung3.enums.EventType;
import iws.g5.uebung3.impls.Food;

/**
 * Class to be implemented by every LivingOrganicObject
 * @author t.ganzert
 *
 */
public abstract class LivingOrganicObject {
	static int actCellId=0;
	
	protected int cellId;
	protected int xPosition;
	protected int yPosition;
	protected int birthIteration;
	protected StateModel env;
	
	public LivingOrganicObject(StateModel env, int birthIteration){
		cellId=actCellId++;
		this.birthIteration=birthIteration;
		this.env=env;
	}
	
	/**
	 * @return an unique unifier for the object
	 */
	public int getCellId(){
		return cellId;
	}
	
	/**
	 * Method for giving the object information about its position
	 * @param x x position
	 * @param y y position
	 */
	public void setPosition(int x,int y){
		this.xPosition=x;
		this.yPosition=y;
	}
	
	public boolean equals(LivingOrganicObject compCell){
		if(this.getCellId()==compCell.getCellId()){
			return true;
		}else{
			return false;
		}
	}
	

	/**
	 * OrganicObject dies and replaces the place with Food
	 */
	public void die() {
		env.removeOrganicObject(xPosition, yPosition);
		env.addOrganicObject(new Food(), xPosition, yPosition);
	}
	
	/**
	 * Method triggert by the timer in every iteration (handles cell behavior) 
	 * @param iteration actual iteration
	 */
	public abstract void onEventTriggered(int iteration, EventType event);
}
